package rabbitMQ;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;
import rabbitMQ.entity.Abc;

import java.io.IOException;

@Component
public class ConsumeController {

    @RabbitListener(bindings = @QueueBinding(
        value = @Queue(name = "ltTestQueue"),
        exchange = @Exchange(name = "ltTestExchange" , type = ExchangeTypes.DIRECT),
        key = "ltTestRoutingKey"
    ))
    @RabbitHandler
    public void aa(Abc str, Message message, Channel channel) {
        MessageProperties messageProperties = message.getMessageProperties();
        long deliveryTag = messageProperties.getDeliveryTag();
        try {
            System.out.println(str);
            channel.basicAck(deliveryTag, false);
        } catch (IOException e) {
            e.printStackTrace();
            try {
                channel.basicReject(deliveryTag, false);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    }



}
